/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package jtmcraft.game.units.states;

import jtmcraft.graphics.Sprite;

/**
 *
 * @author milosz
 */
public abstract class MovableState implements GameUnitState {

    public MovableState() {
    }

    protected void setMoveAction(Sprite sprite, double degree, double i) {
        int direction = (int) (degree / (Math.PI / 8));
        if (i >= 0) {
            switch (direction) {
                case 0:
                    sprite.setSpriteAction(Sprite.eSpriteAction.moveE);
                    break;
                case -1:
                case -2:
                    sprite.setSpriteAction(Sprite.eSpriteAction.moveNE);
                    break;
                case -3:
                    sprite.setSpriteAction(Sprite.eSpriteAction.moveN);
                    break;
                case 1:
                case 2:
                    sprite.setSpriteAction(Sprite.eSpriteAction.moveSE);
                    break;
                case 3:
                    sprite.setSpriteAction(Sprite.eSpriteAction.moveS);
                    break;
            }
        }
        if (i < 0) {
            switch (direction) {
                case 0:
                    sprite.setSpriteAction(Sprite.eSpriteAction.moveW);
                    break;
                case -1:
                case -2:
                    sprite.setSpriteAction(Sprite.eSpriteAction.moveWN);
                    break;
                case -3:
                    sprite.setSpriteAction(Sprite.eSpriteAction.moveN);
                    break;
                case 1:
                case 2:
                    sprite.setSpriteAction(Sprite.eSpriteAction.moveSW);
                    break;
                case 3:
                    sprite.setSpriteAction(Sprite.eSpriteAction.moveS);
                    break;
            }
        }
    }

        protected void setMoveActionDegree(Sprite sprite, int degree) {


            switch(degree % 360) {
                case 0:
                    sprite.setSpriteAction(Sprite.eSpriteAction.moveN);
                    break;
                case 45:
                    sprite.setSpriteAction(Sprite.eSpriteAction.moveNE);
                    break;
                case 90:
                    sprite.setSpriteAction(Sprite.eSpriteAction.moveE);
                    break;
                case 135:
                    sprite.setSpriteAction(Sprite.eSpriteAction.moveSE);
                    break;
                case 180:
                    sprite.setSpriteAction(Sprite.eSpriteAction.moveS);
                    break;
                case 225:
                    sprite.setSpriteAction(Sprite.eSpriteAction.moveSW);
                    break;
                case 270:
                    sprite.setSpriteAction(Sprite.eSpriteAction.moveW);
                    break;
                case 315:
                    sprite.setSpriteAction(Sprite.eSpriteAction.moveWN);
                    break;
                case 360:
                    sprite.setSpriteAction(Sprite.eSpriteAction.moveN);
                    break;

            }
    
    }

    
}
